var c = require('checkAuthority');
var customsDeclaration;
var cabinetNo;
var fenghaoNo;

var addDeclareTemplate = __inline('addDeclare.handlebars');
$('#addDeclareForm').html(addDeclareTemplate);
/*
$('#fenghaoNo').blur(function() {
	customsDeclaration = $('#customsDeclaration').val();
	cabinetNo = $('#cabinetNo').val();
	fenghaoNo = $(this).val();
	check();
});

var reg = /^[0-9]*(\.[0-9]{1,2})?$/;  */

/*costCheck('#trailerCost1');
costCheck('#otherCost1');
costCheck('#customsDeclarationCost1');
costCheck('#trailerPayCost1');
costCheck('#customsDeclarationPayCost1');*/
/*$('#trailerCost1').keyup(function() {
	console.info('ddd');
	var reg = $(this).val().match(/\d+\.?\d{0,2}/);
	var txt = '';
	if(reg != null) {
		txt = reg[0];
	}
	$(this).val(txt);
}).change(function() {
	$(this).keypress();
	var v = $(this).val();
	if(/\.$/.test(v)) {
		$(this).val(v.substr(0, v.length - 1));
	}
});*/
yuki.check('trailerCost');
yuki.check('otherCost');
yuki.check('customsDeclarationCost');
yuki.check('trailerPayCost');
yuki.check('customsDeclarationPayCost');
/*function costCheck(id){
	$(id).blur(function(){
		var cost = $(this).val();

		var hidden = id.substring(0,id.length-1);

		if(!reg.test(cost)){  
	         $('.error-tip').show(500);
	    }else{
	    	$('.error-tip').hide(500);
	    }
	    
		cost = ($(hidden).val()) ? cost : 0;
		$(hidden).val(cost);
	    check();
	});
}

function check(){
	if (customsDeclaration != "" && cabinetNo != "" && fenghaoNo != "" && $('.error-tip').css('display') == 'none') {
		$('#addDeclareForm button[type=submit]').removeAttr('disabled');
	} else {
		$('#addDeclareForm button[type=submit]').attr('disabled', 'disabled');
	}
}*/

$('#addDeclareForm button[type=submit]').on('click', function() {
	$.ajax({
		type: "post",
		url: "./order/addorder.bto",
		async: true,
		cache: false,
		data: $('#addDeclareForm').serialize(),
		success: function(data) {
			var authorityCode = data.code;
			function template() {
				alert('录入成功！');
				window.location.href = "declareManage.html";
			}
			c.authority(authorityCode, template);
		}
	});
});
